home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 176-200 / disk_197 / stevie / sendpacket.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  70 lines

  1. /*
  2.  * Sendpacket.c 
  3.  *
  4.  * An invaluable addition to your Amiga.lib file. This code sends a packet the
  5.  * given message port. This makes working around DOS lots easier. 
  6.  *
  7.  * Note, I didn't write this, those wonderful folks at CBM did. I do suggest
  8.  * however that you may wish to add it to Amiga.Lib, to do so, compile it and
  9.  * say 'oml lib:amiga.lib -r sendpacket.o' 
  10.  */
  11.  
  12. #include <proto/exec.h>
  13. /* #include <exec/ports.h> */
  14. #include <exec/memory.h>
  15. #include <proto/dos.h>
  16.  
  17. /*
  18.  * Function - SendPacket written by Phil Lindsay, Carolyn Scheppner, and Andy
  19.  * Finkel. This function will send a packet of the given type to the Message
  20.  * Port supplied. 
  21.  */
  22.  
  23. long
  24. SendPacket(pid, action, args, nargs)
  25.     struct MsgPort *pid;    /* process indentifier ... (handlers message
  26.                  * port ) */
  27.     long            action,    /* packet type ... (what you want handler to
  28.                  * do )   */
  29.                     args[],    /* a pointer to a argument list */
  30.                     nargs;    /* number of arguments in list  */
  31. {
  32.     struct MsgPort *replyport;
  33.     struct StandardPacket *packet;
  34.  
  35.     long            count, *pargs, res1;
  36.  
  37.     replyport = (struct MsgPort *) CreatePort(NULL, 0);
  38.     if (!replyport)
  39.     return (0);
  40.  
  41.     /* Allocate space for a packet, make it public and clear it */
  42.     packet = (struct StandardPacket *)
  43.     AllocMem((long) sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
  44.     if (!packet) {
  45.     DeletePort(replyport);
  46.     return (0);
  47.     }
  48.     packet->sp_Msg.mn_Node.ln_Name = (char *) &(packet->sp_Pkt);
  49.     packet->sp_Pkt.dp_Link = &(packet->sp_Msg);
  50.     packet->sp_Pkt.dp_Port = replyport;
  51.     packet->sp_Pkt.dp_Type = action;
  52.  
  53.     /* copy the args into the packet */
  54.     pargs = &(packet->sp_Pkt.dp_Arg1);    /* address of first argument */
  55.     for (count = 0; count < nargs; count++)
  56.     pargs[count] = args[count];
  57.  
  58.     PutMsg(pid, packet);    /* send packet */
  59.  
  60.     WaitPort(replyport);
  61.     GetMsg(replyport);
  62.  
  63.     res1 = packet->sp_Pkt.dp_Res1;
  64.  
  65.     FreeMem(packet, (long) sizeof(struct StandardPacket));
  66.     DeletePort(replyport);
  67.  
  68.     return (res1);
  69. }
  70.